package jml.defaultimple.web;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import jml.def.Library;
import jml.defaultimple.util.JMLLoader;

@WebListener
public class ContextListener implements ServletContextListener
{
	public void contextInitialized(ServletContextEvent arg0)
	{
		ServletContext application = arg0.getServletContext();
		String configFileFullname = application.getInitParameter("configFile");
		
		Library library = JMLLoader.load(configFileFullname);
		application.setAttribute("library", library);
		
		String webappRoot = application.getRealPath("");
		WebFacade webFacade = new WebFacade(webappRoot,library);
		application.setAttribute("webFacade", webFacade);
	}

	@Override
	public void contextDestroyed(ServletContextEvent arg0)
	{
	}

}
